package com.xiaoxi.open.design.creation.prototypepattern.product;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * @ClassName UnderlinePenProduct
 * @Description
 * @Author xiaoxi
 * @Date 2023/3/12 15:07
 * @Version 1.0
 */
@Service
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@Data
public class UnderlinePenProduct implements IProduct {

    private char ch ;

    @Override
    public void init() {
        this.ch = '-';
    }

    @Override
    public void use(String str) {
        for (int i = 0 ; i < str.length();i++) {
            System.out.print(ch);
        }
        System.out.println();
        System.out.println(str);
        for (int i = 0 ; i < str.length();i++) {
            System.out.print(ch);
        }
        System.out.println();
    }

    @Override
    public IProduct createClone() {
        try {
            return (IProduct) super.clone();
        } catch (CloneNotSupportedException e) {
            log.error("clone error : {}", e.getMessage());
        }
        return null;
    }

}
